package com.xcm.util;

import java.io.UnsupportedEncodingException;
import java.util.Random;

/**
 * 中文生成器
 *
 * @author 林强
 * @date 2018-04-12 11:15
 */
public class ChineseBuilder {
    /**
     * 随机指定长度生成中文
     *
     * @return
     */
    public static String getRandomName(int nameLength) {
        String str = "";
        int hightPos;
        int lowPos;
        Random random = new Random();
        for (int i = 0; i < nameLength; i++) {
            hightPos = (176 + Math.abs(random.nextInt(39)));
            lowPos = (161 + Math.abs(random.nextInt(93)));
            byte[] b = new byte[2];
            b[0] = (Integer.valueOf(hightPos)).byteValue();
            b[1] = (Integer.valueOf(lowPos)).byteValue();
            try {
                str += new String(b, "GBK");
            } catch (UnsupportedEncodingException e) {
                System.out.println("ChineseBuilder getRandomName 生成指定字数的人名错误：" + e.getMessage());
            }
        }
        return str;
    }
}
